﻿using System;
using System.Collections.Generic;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Media;

namespace HobSoft.SoccerBet2014.Common.Wpf.Converter
{
    public class DataGridHeaderColorConverter : IValueConverter
    {
        public DataGridHeaderColorConverter()
        {
            HeaderBrush = new Dictionary<string, Brush>();
            Default = new SolidColorBrush(Colors.Transparent);
        }
        public Dictionary<string, Brush> HeaderBrush { get; set; }
        public Brush Default { get; set; }
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var header = value as DataGridColumnHeader;
            if (header == null || header.Column == null) return new SolidColorBrush(Colors.Transparent);
            string headKey = header.Column.DisplayIndex.ToString();
            if (HeaderBrush.ContainsKey(headKey))
            {
                return HeaderBrush[headKey];
            }
            return Default;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
